<%--
  Created by IntelliJ IDEA.
  User: Fan307
  Date: 2016/11/2
  Time: 21:03
  To change this template use File | Settings | File Templates.
--%>
<%@page import="java.io.BufferedReader"%>
<%@page import="java.io.FileReader"%>
<%@page import="java.io.File"%>
<%@ page import="java.io.FileInputStream" %>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%
    //String path = request.getContextPath();
    //System.out.println("path=="+path);
    //String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>
<!DOCTYPE html>
<html>
<head>
    <meta name="viewport" content="width=device-width,height=device-height,initial-scale=1.0,maximum-scale=1.0,user-scalable=no">
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Txt文档</title>
</head>
<body>
<%
    //String filePath = request.getSession().getServletContext().getRealPath("/")+"JSP_Ajax"+"\\";
    //System.out.println("filePath=="+filePath);
//    String path ="C:\\";   // 这边文件目录需改成相对路径
    String filepath = request.getParameter("filepath").substring(3);
    //得到对应文档的绝对路径
//    String strFilePath = application.getRealPath("/") + filepath;
    String strFilePath = "D:\\IdeaProjects\\Education\\out\\artifacts\\Education_war_exploded\\res\\computer\\CDUT\\program\\Cplusplus";
    //取出所文件的名字，带有后缀
//    String filename = filepath.substring(strFilePath.lastIndexOf('\\')+1);
//    System.out.print(filename);
    System.out.println(strFilePath);
    File file = new File(strFilePath,"1此为c++文件下的文件.txt");
    FileReader fr = new FileReader(file);  //字符输入流
    BufferedReader br = new BufferedReader(fr);  //使文件可按行读取并具有缓冲功能
    StringBuffer strB = new StringBuffer();   //strB用来存储jsp.txt文件里的内容
    String str = br.readLine();
    while(str!=null){
        strB.append(str).append("<br>");   //将读取的内容放入strB
        str = br.readLine();
    }
    br.close();    //关闭输入流
%>

    <%=strB %>

</body>
</html>
